@extends('layouts.back_stage')
@section('style')
    @parent
    <style>
       .lab{width:220px;line-height:30px;margin-right:10px;margin-bottom: 15px;}
       .sel{width:160px;float:right;font-size: 13px;padding:5px 10px;font-weight: normal;}
       .lbl{width:220px;line-height:30px;margin-right:10px;}
       .lbl2{width:683px;line-height:30px;margin-right:10px;}
       .lbl3{width:247px;line-height:30px;margin-right:10px;}
       .lbl_inp{width:160px;float:right;font-weight: normal}
       .lbl_text{width:622px;height:115px;float:right;font-weight: normal;resize: none;}
       .lbl_btn{float: left;margin-left:610px;margin-top:50px;}
    </style>
@endsection
@section('content')
    <div class="container">
        <div class="row">
            <div style="margin: 30px;"><h3 >添加生产商品的基本信息</h3></div>
            <div class="col-md-10 col-md-offset-1">
                <form role="form" action="/production/store" method="post" >
                    {{ csrf_field() }}
                    <div class="form-group">
                        <label class="lab">品牌：
                            <select name="brand" id="brand" class="address sel">
                                <option value="">请选择</option>
                                @foreach ($brands as $brand)
                                    <option value={{$brand->id}}>{{$brand->brand_name}}</option>
                                @endforeach
                            </select>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="lab" for="category_one">大分类：
                            <select name="category_one" id="category_one" class="address sel pro_select">
                                <option value="">请选择</option>
                                @foreach ($category_one as $value)
                                    <option value={{$value->id}}>{{$value->category_name}}</option>
                                @endforeach
                            </select>
                        </label>
                        <label class="lab" for="category_two">中分类：
                            <select name="category_two" id="category_two" class="address sel pro_select">
                                <option value="">请选择</option>
                            </select>
                        </label>
                        <label class="lab" for="category_three">小分类：
                            <select name="category_three" id="category_two" class="address sel ">
                                <option value="">请选择</option>
                            </select>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="lab">年份：
                            <select name="year" id="year" class="address sel">
                                <option value="{{$year}}" selected>{{$year}}</option>
                                <option value="{{$year-1}}">{{$year-1}}</option>
                                <option value="{{$year+1}}">{{$year+1}}</option>
                            </select>
                        </label>
                        <label class="lab">季度：
                            <select name="quarter" id="quarter" class="address sel">
                                <option value="春季" selected>春季</option>
                                <option value="夏季">夏季</option>
                                <option value="秋季">秋季</option>
                                <option value="冬季">冬季</option>
                            </select>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="lbl">款号：<input class="form-control lbl_inp" type="text" placeholder="请输入款号" id="item" name="item" value="{{ old('item') }}" id="admin_name" name="admin_name" /></label>
                        <label class="lbl">颜色：<input class="form-control lbl_inp" type="text" placeholder="请输入颜色" id="color" name="color" value="{{ old('color') }}" id="admin_name" name="admin_name" /> </label>
                    </div>
                    <div class="form-group">
                        <label class="lbl2">成分：
                            <textarea class="lbl_text" name="made_info" id="admin_name" name="admin_name"></textarea>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="lbl">数量/手：<input class="form-control lbl_inp" type="text" placeholder="手" id="num" name="num" value="{{ old('num') }}" id="admin_name" name="admin_name" /></label>
                        <label class="lbl3">每手几件/件：<input class="form-control lbl_inp" type="text" placeholder="件" id="piece" name="piece" value="{{ old('piece') }}" id="admin_name" name="admin_name" /></label>
                    </div>
                    <div class="form-group">
                        <button type='submit' class='btn btn-success lbl_btn'>完成</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    @include('errors.list')
    <script>
        $('[name=category_one]').change(function () {
            $('[name=category_two]').html("<option>请选择</option>");
            $('[name=category_three]').html("<option>请选择</option>");
        });

        $('.pro_select').change(function () {
            var category = $(this).val();
            var type = $(this).attr('name');
            if(type == 'category_one'){
                type = 'category_two';
            }else if(type == 'category_two')
            {
                type = 'category_three';
            }
            $.ajax({
                url:'/getCategory',
                type:'POST',
                data:{
                    'category':category,
                    'type':type
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    if(data.success == true)
                    {
                        $('[name='+type+']').html("<option>请选择</option>");
                        $(data.data).each(function () {
                            var option = "<option value="+this.id+">"+this.category_name+"</option>"
                            $('[name='+type+']').append(option);
                        })
                    }
                }
            })
        });
    </script>
@endsection